package com.SparkCore.RDD.Operator.Transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}


/**
 *将 List(List(1,2),3,List(4,5))进行扁平化操作
 */
object Spark04_RDD_Operator_Transform2 {

  def main(args: Array[String]): Unit = {

    //创建环境
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("RDD")
    val sparkContext = new SparkContext(sparkConf)

    //创建RDD算子 -- flatMap

    val rdd = sparkContext.makeRDD(List(
      List(1, 2), 3, List(4, 5)
    ))
    val flatRDD = rdd.flatMap {
      case list: List[_] => list
      case dat => List(dat)
    }
    flatRDD.collect().foreach(println)

    //关闭环境
    sparkContext.stop()
  }
}
